/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.refunite.mobile.s60.widget;

import java.util.Vector;
import javax.microedition.lcdui.ChoiceGroup;
import org.javarosa.core.model.SelectChoice;
import org.javarosa.core.model.data.StringData;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryPrompt;

/**
 *
 * @author I040022
 */
public class ChoiceGroupQuestionWidget extends AbstractFormWidget{
    private CustomChoiceGroup customChGroup;

    public ChoiceGroupQuestionWidget(FormEntryController formEntryController, FormEntryPrompt formEntryPrompt, int index){
        super(formEntryController, formEntryPrompt, index);
        this.customChGroup = new CustomChoiceGroup(null, ChoiceGroup.EXCLUSIVE);
        Vector selectableItems = formEntryPrompt.getQuestion().getChoices();
        for(int j = 0; j<selectableItems.size(); j++){
            SelectChoice selectItem = (SelectChoice)selectableItems.elementAt(j);
            this.customChGroup.append(selectItem.getCaption(), null, selectItem.getValue());
        }
        this.append(customChGroup);
    }

    public void saveAnswer(){
        StringData answer = new StringData(this.customChGroup.getSelectedItem());
        this.formEntryController.answerQuestion(formEntryPrompt.getIndex(), answer);
    }
}
